# -*- coding: utf-8 -*-
# @Author  : pony.guan
# @Time    : 2022/2/14 18:16
# Description:

import time
import json
import pandas as pd

with open('11') as f:
    data = json.loads(f.read())
    # l1 = list(data.keys())
    # for k in l1:
    #     ts = data[k]
    #     for t in ts:
    #         if type(t) == dict and t.get('id') == '1724731137371150080' :
    #             print(k)
    # assert 1 == 2
    # # transport_tasks = data['transportTask']
    transport_tasks = data['wmsTask']
    data1 = []
    data2 = []
    for t in transport_tasks:
        # TASK_2021120200000182
        code = t['code']
        # state = t['state']

        # if t.get('id') == "1724730239891805952":
        #     print(t)
        #     break

        # if t.get('parentTaskCode', '')[5:13] == '20211221':
        if 1:
            if code.startswith('CK') and t.get('state') == 'FINISHED' and 'created' in t.keys():
                print(t)
                ct = t['created'] / 1000
                ct = time.localtime(ct)
                ct = time.strftime('%Y-%m-%d %H:%M:%S', ct)
                data1.append(
                    {
                        'code': code,
                        # 'parentTaskCode': t['parentTaskCode'],
                        # 'intendedRobotCode': t['intendedRobotCode'],
                        # 'containerCode': t['containerCode']
                        'state': 'FINISHED',
                        'created': 'ct'
                    }
                )

            # elif code.startswith('return'):
            #     data2.append(
            #         {
            #             'code': code,
            #             'parentTaskCode': t['parentTaskCode'],
            #             'intendedRobotCode': t['intendedRobotCode'],
            #             'containerCode': t['containerCode']
            #         }
            #     )

    df1 = pd.DataFrame(data1)
    print(df1.head())
    # df2 = pd.DataFrame(data2)
    # print(df1.head())
    # print(df2.head())
    # write = pd.ExcelWriter('1.xlsx')
    # df1.to_excel(write, sheet_name='sheet1')
    # df2.to_excel(write, sheet_name='sheet2')
    # write.save()
